import ProTable from '@ant-design/pro-table';
import React, {useState} from 'react';
import {defaultPagination, paginationTool} from '@/utils/util';
import {useMount, useRequest} from 'ahooks';

import {getResult} from '@/services/ant-design-pro/attribute';
import { editUsersReg, findByPageList} from '@/services/ant-design-pro/users';
import {ProFormSelect} from "@ant-design/pro-form";
import {findByAgentBySelectList} from "../../services/ant-design-pro/agent";
import FormModalBtn from "../../components/FormModalBtn";
import {findByTaoCanPageList} from "@/services/ant-design-pro/taocan";
import EditDialog from "@/pages/taocan/editDialog";



//
const cloneTbale = () => {
  const [pagination, setPagination] = useState<API.Pagination> ( defaultPagination () );
  const {
    run: fetchByPageList,
    refresh,
    data: dataList,
    loading,
  } = useRequest ( findByTaoCanPageList, {
    debounceWait: 100,
    manual: true,
  } );

  const columns = [{
    title: "编号",
    key: "id",
    dataIndex: "id",
    search: false,
  }, {
    title: "套餐名称",
    key: "name",
    dataIndex: "name",


  },{
    title: '当前等级',
    dataIndex: 'relationAgentName',
    key: 'relationAgentName',
    search: false,
  },  {
    title: '下单代理等级',
    dataIndex: 'agentName',
    key: 'agentName',
    search: false,
  },
     {
    title: "支付金额",
    key: "paymentAmount",
    dataIndex: "paymentAmount",
    valueType: 'money',
    search: false,
  },
    {
      title: "优惠金额",
      key: "discountAmount",
      dataIndex: "discountAmount",
      valueType: 'money',
      search: false,
    }, {
      title: "支付总额",
      key: "totalAmount",
      dataIndex: "totalAmount",
      valueType: 'money',
      search: false,
    },
    {
      title: "产品总数",
      key: "quantity",
      dataIndex: "quantity",
      search: false,
    },  {
      title: "时间",
      key: "createDate",
      dataIndex: "createDate",
      valueType: 'date',
      search: false,
      // initialValue: [moment().calendar(), moment().add(10, 'days').calendar()],
    },{
      title: "时间",
      key: "createDate",
      dataIndex: "createDate",
      valueType: 'dateRange',
      hideInTable: true,
      // initialValue: [moment().calendar(), moment().add(10, 'days').calendar()],
    }, {
      title: "操作人员",
      key: "operatorName",
      dataIndex: "operatorName",
      search: false,

    },{
      title: "操作",
      key: "operatorName",
      dataIndex: "operatorName",
      search: false,
      render:(_: any, row: API.TaoCanMaster, index: any, action: any)=>[<EditDialog taocanId={row?.id} row={row} onSuccess={refresh}/>]

    }]
  useMount ( () => {
    fetchByPageList ({});

  } );

  // @ts-ignore
  return (
    <ProTable<API.TaoCanMaster>
      toolBarRender={()=>[<EditDialog taocanId={0}  onSuccess={refresh} />]}
      onDataSourceChange={(d) => {
        console.log ( 'onDataSourceChange', d );
      }}
      onLoad={(d) => {
        // 数据加载完操作
        console.log ( 'onDataSourceChange', d );
      }}
      dataSource={dataList?.data?.list}
      loading={loading}
      pagination={paginationTool ( pagination, dataList?.data?.total, (data1: API.Pagination) => {
        setPagination ( data1 );

        fetchByPageList ( {...data1} );
      } )}
      search={{
        defaultCollapsed: false,
        labelWidth: 'auto',
      }}
      onSubmit={(params) => {
        fetchByPageList ( params );
        console.log ( 'onSubmit', params );
      }}
      cardBordered={true}
      columns={columns}
     request={editUsersReg}
    ></ProTable>
  );
};

export default cloneTbale;
